<template>
	<view>
		<dsl-navbar title="个人资料" bgTopImg="#ffffff" isBack="true"></dsl-navbar>
		<view class="">

			<view class="align-center  bg-white rowsb padding solid-bottom">
				<view class="text-gray">头像</view>
				<view class="align-center">
					<image @click="avatarUpload()" class="user_image" :src="avatar?avatar:''"></image>
					<text class="cuIcon-right text-gray"></text>
				</view>
			</view>
			<view class="align-center bg-white  solid-bottom padding rowsb">
				<view class="align-center">
					<view class="text-gray">昵称</view>
					<input v-model="userName" type="text" class="margin-left" placeholder="请输入" />
				</view>
				<view class="cuIcon-right"></view>
			</view>
	<!-- 		<view class="align-center bg-white solid-bottom padding rowsb" @click="sexMen()">
				<view class="text-gray">性别</view>
				<view>
					<view class="">{{gender==0?'男生':'女生'}}</view>
				</view>
			</view> -->
	
			<view class="align-center  bg-white solid-bottom padding rowsb margin-top ">
				<view class="align-center">
					<view class="text-gray">身高</view>
					<input v-model="stature" type="text" class="margin-left" placeholder="请输入" />
				</view>
				<view class="cuIcon-right"></view>
			</view>
			<view class="align-center bg-white  padding rowsb">
				<view class="align-center">
					<view class="text-gray">年龄</view>
					<input v-model="age" type="text" class="margin-left" placeholder="请输入" />
				</view>
				<view class="cuIcon-right"></view>
			</view>
			<view class="align-center bg-white  padding rowsb margin-top" @click="$tools.push('/pages/user/modules/meritForm?id='+userInfo.id)">
				<view class="align-center">
					<view class="text-gray">个人优势</view>
				</view>
				<view class="cuIcon-right"></view>
			</view>
		</view>

		<view class="submit_form animation-scale-up" @click="submitForm()">
			提交
		</view>

	</view>
</template>

<script>
	import {
		updateUser,
		getUserInfo
	} from '@/common/path.js'
	import {
		updataImgList
	} from '@/common/updataImgList.js'
	export default {
		data() {
			return {
				list: ['男', '女'],
				gender: 0, //性别
				avatar: '', //头像
				userName: '', //昵称
				userInfo: {}, //用户信息
				age:1,//年龄
				stature:1,//身高
			}
		},
		//生命周期函数
		onReady() {},
		onLoad() {},
		onShow() {
			this.getUserInfo() //用户信息
		},
		methods: {
			//性别选择
			sexMen() {
				let v = this
				uni.showActionSheet({
					itemList: ['男', '女'],
					success: function(res) {
						if (res.tapIndex == 0) {
							v.gender = 0
						} else {
							v.gender = 1
						}
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			//上传头像
			avatarUpload() {
				updataImgList().then(res => {
					if (res.code == 0) {
						this.avatar = res.data
					} else {
						this.$tools.showToast('图片上传失败')
					}
				})
			},
			//获取用户信息
			getUserInfo() {
				let data = {
					id: uni.getStorageSync('userInfo').id
				}
				this.Http.POST(getUserInfo, data)
					.then((res) => {
						if (res.code == 0) {
							console.log('[用户信息]', res);
							this.userInfo = res.data
							this.avatar = res.data.avatar
							this.userName = res.data.userName
							this.gender = res.data.gender
							this.age = res.data.age
						}
					})
			},
			//提交用户资料
			submitForm() {
				let v = this
				let data = {
					userName: v.userName,
					avatar: v.avatar, //头像
					id: uni.getStorageSync('userInfo').id,
					gender:this.gender,//性别 0男 1女
					age:this.age //年龄
				}
				v.Http.POST(updateUser, data)
					.then((res) => {
						if (res.code == 0) {
							setTimeout(() => {
								v.$tools.back()
							}, 1000)
							v.$tools.showToast2(res.msg)
						} else {
							v.$tools.showToast(res.msg)
						}
					})
			}
		},
		computed: {},
		components: {}
	}
</script>

<style scoped>
	.user_image {
		width: 98rpx;
		height: 98rpx;
		background: #eeeeee;
		border-radius: 50%;
		opacity: 1;
	}


	.text-gray {
		color: #9AA2B5;
	}

	page {
		background: #F7F6FA;
	}

	.submit_form {
		width: 658rpx;
		height: 90rpx;
		background: #EAA019;
		opacity: 1;
		border-radius: 45rpx;
		text-align: center;
		line-height: 90rpx;
		color: white;
		margin: 0 auto;
		margin-top: 60rpx;
	}
</style>
